import org.apache.commons.lang.StringUtils;

import java.text.DecimalFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/*
 * @author changfei
 * @date  2023/11/30 19:30
 * @description
 */
public class TestString {
    public static void main(String[] args) {


        String dstr = "20231112";
        String dtstr0 = "202311101112";
        String dtstr1 = "20231110111";
        String dtstr2 = "20231210111211";
        String dtstr3 = "2023121ssss";

        System.out.println("=" + transferDateTimeStr(dstr));
        System.out.println("=" + transferDateTimeStr(dtstr0));
        System.out.println("=" + transferDateTimeStr(dtstr1));
        System.out.println("=" + transferDateTimeStr(dtstr2));
        System.out.println("=" + transferDateTimeStr(dtstr3));

        System.out.println(getAmtRMB("ss"));
        System.out.println(getAmtRMB(""));
        System.out.println(getAmtRMB("0"));
        System.out.println(getAmtRMB("0"));
        System.out.println(getAmtRMB("100"));
        System.out.println(getAmtRMB("1000000.1"));
        System.out.println(getAmtRMB("100000000.2"));
        System.out.println(getAmtRMB("-1"));
        System.out.println(getAmtRMB("-1.1"));
        System.out.println(getAmtRMB("-1.12"));
        System.out.println(getAmtRMB("-1.123"));

    }

    public static String getAmt(String amt) {

        DecimalFormat df = new DecimalFormat("##,##0.00");
        return getAmt(amt, df);
    }

    public static String getAmt(String amt, DecimalFormat df) {
        if (StringUtils.isEmpty(amt)) {
            amt = "0";
        }
        try {
            return df.format(Double.parseDouble(amt));
        } catch (Exception e) {
            return "0.00";
        }
    }
    public static String getAmtRMB(String amt,DecimalFormat df) {
        String amtTrans = getAmt(amt,df);
        if (amtTrans.startsWith("-")) {
            amtTrans = amtTrans.substring(1);
            amtTrans = "-¥" + amtTrans;
        } else {
            amtTrans = "¥" + amtTrans;
        }
        return amtTrans;
    }
    public static String getAmtRMB(String amt) {
        String amtTrans = getAmt(amt);
        if (amtTrans.startsWith("-")) {
            amtTrans = amtTrans.substring(1);
            amtTrans = "-¥" + amtTrans;
        } else {
            amtTrans = "¥" + amtTrans;
        }
        return amtTrans;
    }


    public static String transferDateTimeStr(String dtStr) {
        SimpleDateFormat sourceSimpleDateFormat = new SimpleDateFormat("yyyyMMddHHmm");
        SimpleDateFormat destSimpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm");
        return transferDateTimeStr(dtStr, sourceSimpleDateFormat, destSimpleDateFormat);
    }

    public static String transferDateTimeStr(String dtStr, SimpleDateFormat sourceSimpleDateFormat, SimpleDateFormat destSimpleDateFormat) {
        try {
            int size = 12;
            if (dtStr.length() > size) {
                dtStr = dtStr.substring(0, size);
                System.out.println("==" + dtStr);
            }
            String transDtStr = StringUtils.rightPad(dtStr, size, "0");
            //System.out.println(dtStr.substring(0,11));
            System.out.println("原始:" + dtStr + " 转换后:" + transDtStr);
            return destSimpleDateFormat.format(sourceSimpleDateFormat.parse(transDtStr));
        } catch (Exception e) {
            System.out.println(e);
        }
        return "";
    }
}
